package com.aruba.service.impl;

import com.aruba.mapper.UserMapper;
import com.aruba.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
//@Transactional 所有方法开启事务
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional //该方法开启事务
    public int transMoney(int from, int to, int money) {
        userMapper.updateMoney(from, -money);
        int a = 1 / 0;//模拟一个异常
        userMapper.updateMoney(to, money);
        return 0;
    }
}
